package codeTop;

public class q98 {
    public boolean isValidBST(TreeNode root) {
        return dfs(root,Long.MIN_VALUE,Long.MAX_VALUE);
    }
    boolean dfs(TreeNode node,long l,long r){
        if (node == null) {
            return true;
        }
        if (node.val <= l || node.val >= r) {
            return false;
        }
        boolean left = true,right = true;
        if (node.left != null) {
            left = dfs(node.left, l, node.val);
        }
        if (node.right != null) {
            right = dfs(node.right, node.val, r);
        }
        return left&&right;
    }

    public static void main(String[] args) {
        q98 q = new q98();
        TreeNode node = new TreeNode(-2147483648);
        node.left = new TreeNode(-2147483648);
        System.out.println(q.isValidBST(node));
    }
}
